//
//  YMProblemMainListCell.m
//  YMMedical
//
//  Created by y s on 2023/7/26.
//

#import "YMProblemMainListCell.h"

@interface YMProblemMainListCell ()

@property (nonatomic, strong) UIView *vBg;
@property (nonatomic, strong) UIImageView *imgvIcon;
@property (nonatomic, strong) UILabel *lblName;
@property (nonatomic, strong) UILabel *lblDes;
@property (nonatomic, strong) UIImageView *imgvArrow;

@end

@implementation YMProblemMainListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI methods
- (void)setUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    [self.contentView addSubview:self.vBg];
    [self.vBg addSubview:self.lblName];
    [self.vBg addSubview:self.imgvIcon];
    [self.vBg addSubview:self.lblDes];
    [self.vBg addSubview:self.imgvArrow];

    [self.vBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.top.mas_equalTo(0);
    }];
    [self.imgvIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.top.mas_equalTo([SFitUtil fit:15]);
        make.size.mas_equalTo([SFitUtil fitSize:24 height:24]);
    }];
    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.imgvArrow.mas_left).offset([SFitUtil fit:-5]);
        make.centerY.equalTo(self.imgvIcon);
        make.left.equalTo(self.imgvIcon.mas_right).offset([SFitUtil fit:10]);
    }];
    [self.imgvArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.centerY.equalTo(self.imgvIcon);
        make.size.mas_equalTo([SFitUtil fitSize:24 height:24]);
    }];
    [self.lblDes mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([SFitUtil fit:54]);
        make.left.mas_equalTo([SFitUtil fit:47]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.bottom.mas_equalTo([SFitUtil fit:-15]);
    }];
    [self.lblDes mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([SFitUtil fit:54]);
        make.left.mas_equalTo([SFitUtil fit:47]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.bottom.mas_equalTo(0);
    }];
}


#pragma mark - public methods
+ (CGFloat)getCellHeight{
    return [SFitUtil fit:54];
}
- (void)setIsChoose:(BOOL)isChoose{
    _isChoose = isChoose;
    self.lblDes.hidden = !isChoose;
    [self.lblDes mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([SFitUtil fit:54]);
        make.left.mas_equalTo([SFitUtil fit:47]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        if (isChoose){
            make.bottom.mas_equalTo([SFitUtil fit:-15]);
        }else{
            make.bottom.mas_equalTo(0);
        }
    }];
    self.imgvArrow.image = [UIImage imageNamed:isChoose ? @"tools_arrow_up_icon":@"tools_arrow_down_icon"];
}
- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    self.lblName.text = [SDataUtil stringOf:dict[@"vxuqvzuiokgnk8la"] valid:@""];
    self.lblDes.text = [SDataUtil stringOf:dict[@"1nagigka1p37iqm9"] valid:@""];
}


#pragma mark - setter and getter
- (UIView *)vBg{
    if (_vBg == nil){
        _vBg = [[UIView alloc] init];
        _vBg.backgroundColor = STheme.D9;
        _vBg.layer.cornerRadius = [SFitUtil fit:8];
        _vBg.clipsToBounds = YES;
    }
    return _vBg;
}
- (UILabel *)lblName{
    if (_lblName == nil){
        _lblName = [[UILabel alloc] init];
        _lblName.textColor = STheme.D1;
        _lblName.font = [SFitUtil fitBoldFont:14];
    }
    return _lblName;
}
- (UILabel *)lblDes{
    if (_lblDes == nil){
        _lblDes = [[UILabel alloc] init];
        _lblDes.textColor = STheme.D3;
        _lblDes.font = [SFitUtil fitFont:12];
        _lblDes.numberOfLines = 0;
        _lblDes.hidden = YES;
    }
    return _lblDes;
}
- (UIImageView *)imgvIcon{
    if (_imgvIcon == nil){
        _imgvIcon = [[UIImageView alloc] init];
        _imgvIcon.image = [UIImage imageNamed:@"mine_problem_list_icon"];
    }
    return _imgvIcon;
}
- (UIImageView *)imgvArrow{
    if (_imgvArrow == nil){
        _imgvArrow = [[UIImageView alloc] init];
        _imgvArrow.image = [UIImage imageNamed:@"tools_arrow_down_icon"];
    }
    return _imgvArrow;
}


@end
